import instance from '../../utils/http'
import { reqSwiperData } from '../../api/index'
Page({
  data: {
    avatarUrl: ''
  },
  async handler() {
    const res = await reqSwiperData()
    console.log(res)

    // const res = await instance.get('/index/findBanner')
    // console.log(res)

    // const res = await instance.get('/cart/getCartList').catch((err) => {
    //   console.log(err)
    //   return err
    // })
    // console.log(res)

    // instance
    //   .request({
    //     url: 'https://gmall-prod.atguigu.cn/mall-api/index/findBanner',
    //     method: 'Get'
    //   })
    //   .then((res) => {
    //     console.log(res)
    //   })
    // /cart/getCartList
    // const res = await instance.get('/index/findBanner', null, { isLoading: false })
    // console.log(res)
    // instance.get('/index/findBanner').then(() => {
    //   instance.get('/index/findBanner').then(() => {})
    // })
  },
  handler1() {
    wx.request({
      url: 'https://gmall-prod.atguigu.cn/mall-api/index/findBanner',
      method: 'GET',
      timeout: 100,
      // timeout: 100, 测试网络超时，需要调整网络
      success: (res) => {
        console.log('只要成功接收到服务器返回，不管状态是多少，都会进入 success 回调')
        console.log(res)
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },
  async allHeadler() {
    // await instance.get('/index/findBanner')
    // await instance.get('/index/findCategory1')
    // await instance.get('/index/findBanner')
    // await instance.get('/index/findCategory1')
    // await Promise.all([instance.get('/index/findBanner'), instance.get('/index/findCategory1'), instance.get('/index/findBanner'), instance.get('/index/findCategory1')])
    const res = await instance.all(
      instance.get('/index/findBanner'),
      instance.get('/index/findCategory1'),
      instance.get('/index/findBanner'),
      instance.get('/index/findCategory1'),
      instance.get('/index/findBanner'),
      instance.get('/index/findCategory1'),
      instance.get('/index/findBanner'),
      instance.get('/index/findCategory1')
    )
    console.log(res)
  },
  async chooseavatar(event) {
    const { avatarUrl } = event.detail
    const { data: avatar } = await instance.upload('/fileUpload', avatarUrl, 'file')
    // console.log(res)
    this.setData({
      avatarUrl: avatar
    })
    // const { avatarUrl} = event.datail
    // wx.uploadFile({
    //   filePath: avatarUrl,
    //   name: 'file',
    //   url: 'https://gmall-prod.atguigu.cn/mall-api/fileUpload',

    //   success: (res) => {
    //     res.data = JSON.parse(res.data)
    //     this.setData({
    //       avatarUrl = rea.data.data
    //     })
    //   },
    // })
  }
})
